package com.syg.service.impl;

import com.syg.domain.Person;
import com.syg.service.OccupationInterface;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author syg
 */
@Service
public class OccupationHandler {

    @Resource
    DoctorService doctorService;


    /**
     * 有name多实现类,为什么注入的是AnnotationConfigServletWebServerApplicationContext?
     */
    @Resource
    private ApplicationContext applicationContext;

    public void occupationHandler(Person person) {
        // 为什么写spring的接口,却不能获取spring的实现类？
        Map<String, OccupationInterface> beans = applicationContext.getBeansOfType(OccupationInterface.class);
        for (OccupationInterface service : beans.values()) {
            service.checkPerson(person);
        }
        doctorService.save(person);
    }

}
